/*
 * File Name:               RectItemDrawer.cs
 * 
 * Description:             普通类
 * Author:                  高锐 <gaor2012@gmail.com>
 * Create Date:             2016/12/05
 */

using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer(typeof(XVector2))]
public class XVector2Drawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // Using BeginProperty / EndProperty on the parent property means that
        // prefab override logic works on the entire property.
        EditorGUI.BeginProperty(position, label, property);

        // Draw label
        //position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        // Don't make child fields be indented
        int indent = EditorGUI.indentLevel;
        EditorGUI.indentLevel = 0;
         
        Rect p1 = new Rect(position.x, position.y, position.width / 2, position.height);
        var x = property.FindPropertyRelative("x");
        var xv = x.FindPropertyRelative("raw");
        float value = XNumber.create_row(xv.intValue);
        value = EditorGUI.FloatField(p1, value);
        xv.intValue = ((XNumber)value).raw;

        Rect p2 = new Rect(position.x + position.width / 2, position.y, position.width / 2, position.height);
        var y = property.FindPropertyRelative("y");
        var yv = y.FindPropertyRelative("raw");
        float yvalue = XNumber.create_row(yv.intValue);
        yvalue = EditorGUI.FloatField(p2, yvalue);
        yv.intValue = ((XNumber)yvalue).raw;

        // Set indent back to what it was
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }
}
